<template>
	<view>
		<longbingbing-app-check-auth type="save" ref="app_check_item" @confirm="toConfirmUpload"></longbingbing-app-check-auth>
	</view>
</template>

<script>
	import permision from '@/utils/permission.js'
	import {
		mapState,
		mapActions,
		mapMutations
	} from "vuex"
	export default {
		components: {},
		props: {},
		mounted() {},
		data() {
			return {
				filePath: ''
			}
		},
		computed: mapState({
			primaryColor: state => state.config.configInfo.primaryColor,
			subColor: state => state.config.configInfo.subColor,
		}),
		methods: {
			...mapActions(['getConfigInfo', 'getUserInfo']),
			...mapMutations(['updateUserItem']),
			previewImage(param) {
				let {
					current,
					urls
				} = param
				let that = this
				uni.previewImage({
					current,
					urls,
					longPressActions: {
						itemList: ['保存图像'],
						success: function(data) {
							that.filePath = urls[data.index]
							uni.closePreviewImage()
							that.$refs.app_check_item.open()
						},
						fail: function(err) {
							console.log(err.errMsg);
						}
					}
				});
			},
			async toConfirmUpload() {
				let status = await permision.requestAndroid('android.permission.WRITE_EXTERNAL_STORAGE')
				if (status === null || status === 1) {
					status = 1
				}
				if (status === 1) {
					let {
						filePath
					} = this
					let [err, success] = await uni.saveImageToPhotosAlbum({
						filePath
					})
					if (err) return;
					uni.showToast({
						icon: 'none',
						title: '保存成功'
					})
					return
				}
				if (status === -1) {
					permision.gotoAppSetting()
					return
				}
			}
		},
	}
</script>

<style scoped lang="scss">
	.choose-upload-popup {
		width: 100%;

		.item-list {
			width: 100%;
		}

		.item-child {
			height: 90rpx;
		}
	}
</style>